#ifndef HISTORY_H
#define HISTORY_H

#include <QWidget>
#include <QtCharts>
#include <QSqlQueryModel>
#include <QSqlRecord>
#include <QSqlQuery>

#include "parameter.h"

using namespace QtCharts;

namespace Ui
{
class history;
}

class History : public QWidget
{
    Q_OBJECT

public:
    explicit History(QWidget* parent = nullptr);
    ~History();

private slots:
    void itemClicked(QModelIndex index);
    void alarmClicked(QModelIndex index);
    void on_btnClose_clicked();
    void on_RecPageFrist_clicked();
    void on_RecPagePrevious_clicked();
    void on_RecPageNext_clicked();
    void on_RecPageEnd_clicked();
    void on_cBoxRecord_currentIndexChanged(int index);
    void on_cBoxAlarm_currentIndexChanged(int index);
    void on_AlarmPageFrist_clicked();
    void on_AlarmPagePrevious_clicked();
    void on_AlarmPageNext_clicked();
    void on_AlarmPageEnd_clicked();

private:
    Ui::history* ui;
    QLineSeries* series;
    QChart* chart;
    QDateTimeAxis* axisX;
    QValueAxis* axisY;
    QSqlQueryModel* model, *alarmmodel;
    QModelIndex recChannelIndex,
                alarmChannelIndex; // 保存当前通道号
    int recPage, recPages, recSize = 3000, alarmPage,
                           alarmPages, alarmSize = 3000;

    void initChart();
    void initChannel();
    void initTableView();
    void initAlarmView();
    void showRecord(QModelIndex index);
    void showAlarm(QModelIndex index);

signals:
    void recPageChanged();
    void alarmPageChanged();
};

#endif // HISTORY_H
